<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page language="java" session="false" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>

<%
//    Integer pageA = "".equals(request.getParameter("page")) || request.getParameter("page")==null ? 1 : Integer.parseInt(request.getParameter("page"));
//    request.setAttribute("pageA",pageA);
//    String tag = request.getParameter("tag");
//    request.setAttribute("tag",tag);
%>

<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
    <title>测试接口 - 资源链-管理后台</title>
    <!-- 最新版本的 Bootstrap 核心 CSS 文件 -->
    <link rel="stylesheet" href="/static/css/bootstrap.min.css" />
    <style type="text/css">*{margin:0; padding:0;} body{overflow-x: hidden;}</style>
    <script type="text/javascript" src="/static/js/jquery-1.8.3.min.js"></script>

</head>
<body>

<div class="row" style="padding:30px;">
    <div class="col-md-12" style="text-align: right;">
        <a href="/joinadmin/logout">退出管理后台</a>
    </div>

</div>




<style type="text/css">
    .tanchuang { display:flex; width:100%; height:100%; justify-content: center; align-items: center; overflow:hidden; }
    .tanchuang .tanchuang_con { width: 600px; height: auto; padding: 30px; background-color: #fff; }
    .tanchuang .tanchuang_con h6 { display:block; width:100%; height:auto; text-align: right; cursor:pointer; overflow:hidden; }
    .tanchuang .tanchuang_con dl { display:block; width:100%; height:auto; padding:10px; box-sizing:border-box; background-color:#f2f2f2; overflow:hidden; }
    .tanchuang .tanchuang_con dl dt { display:inline-block; float:left; width:100%; line-height: 1.6; overflow:hidden; }
    .tanchuang .tanchuang_con dl dd { display:inline-block; float:left; width:100%; margin-top:10px; line-height:1.4; overflow:hidden; }
    .tanchuang .tanchuang_con dl dd p { display:inline-block; float:left; width:100%; font-size:14px; color:#000000; overflow:hidden; }
    .tanchuang .tanchuang_con dl dd p i { display:inline-block; float:right; text-align: right; cursor:pointer; overflow:hidden; }

</style>
<div id="tanchuang" class="tanchuang" data-id="">
    <b class="login" style="display:block; width:100px;height:100px; cursor:pointer;">登录测试</b>
    <div class="tanchuang_con">
        <dl>
            <dt>我的标签：</dt>
            <dd>
<%--                <p><b>标签1</b><i data-tagid="1">DELETE</i></p>--%>
<%--                <p><b>标签2</b><i data-tagid="1">DELETE</i></p>--%>
            </dd>
        </dl>
        <input type="text" placeholder="输入需增加的标签" id="tagInput"/>
        <button>新增标签</button>
    </div>
</div>
<script type="text/javascript">
    $(function(){
        function onDeduplication(arr) {
            var result = [], hash = {};
            for (var i = 0, elem; (elem = arr[i]) != null; i++) {
                if (!hash[elem]) {
                    result.push(elem);
                    hash[elem] = true;
                }
            }
            return result;
        }


        //获取用户ID=1 的所有关系链
        $.ajax({
            type: 'get',
            url:"/joinweixinapp/1/userDetails",
            data:"",
            success:function(res){
                if(res.code == "200"){
                    //我的信息
                    var totalTagsScore = 0; //资源 - 总分
                    var tagsTotalName = []; //全部Tags名称（需移除重复数据，并且没有自己的）
                    var subordinateTagsNum = 0; //我的资源（取关联所有的Tabs总数）
                    var subordinateNetworkNum = 0; //我的人脉（取关联所有人员总数）
                    var networkNum = 0; //我的直属人脉（数）

                    var newList = res.data.list;
                    var userTags = res.data.userObj.tags.split(",").filter(function (item) {
                        return item && item.trim();
                    });
                    subordinateTagsNum += userTags.length; //加入自己Tags资源
                    totalTagsScore += (userTags.length*30); //加入自己Tags资源积分
                    if(newList.length > 0){
                        for(var s=0; s<newList.length; newList++){ //我的直属
                            networkNum++;
                            subordinateNetworkNum++;
                            var tagsA = newList[s].tags.split(",").filter(function (item) {
                                return item && item.trim();
                            });
                            tagsTotalName = tagsTotalName.concat(tagsA); //合并二级用户Tags名称
                            subordinateTagsNum += tagsA.length; //加入二级用户Tags资源
                            totalTagsScore += 30;
                            totalTagsScore += (tagsA.length*10); //加入二级用户Tags资源积分

                            //第三级关系
                            var relationList = newList[s].contacts_relation_user;
                            if(relationList.length > 0){
                                for(var r=0; r<relationList.length; r++){
                                    subordinateNetworkNum++;
                                    var tagsB = relationList[r].tags.split(",").filter(function (item) {
                                        return item && item.trim();
                                    });
                                    tagsTotalName = tagsTotalName.concat(tagsB); //合并三级用户Tags名称
                                    subordinateTagsNum += tagsB.length; //加入三级用户Tags资源
                                    //totalTagsScore += 50;
                                    //totalTagsScore += (tagsB.length*10); //加入三级用户Tags资源积分
                                }
                            }
                        }

                        //结果输出
                        console.log(tagsTotalName);
                        console.log(onDeduplication(tagsTotalName));
                        console.log("资源总积分："+ totalTagsScore);
                        console.log("全部Tags名称：#"+ onDeduplication(tagsTotalName).join(" #"));
                        console.log("我的资源："+ subordinateTagsNum);
                        console.log("我的人脉："+ subordinateNetworkNum);
                        console.log("我的直属人脉："+ networkNum);


                    }

                    //我的标签
                    var tagsList = res.data.tags;
                    var tagHtml = '';
                    for(var i=0; i<tagsList.length; i++){
                        tagHtml += '<p><b>'+tagsList[i].tagname+'</b><i data-tagid="'+tagsList[i].tagid+'">DELETE</i></p>';
                    }
                    $(".tanchuang .tanchuang_con dl dd").html(tagHtml);

                }else{
                    console.log(res.message);
                }

            },
            error:function(err){
                alert("请求服务出错");
            }
        });



        //新增标签
        $(".tanchuang .tanchuang_con button").on("click",function(){
            var inputTag = $("#tagInput").val().trim();
            if(inputTag != ""){
                $.ajax({
                    type: 'POST',
                    url:"/joinweixinapp/1/setTab",
                    data:{"tagname":inputTag},
                    success:function(res){
                        if(res.code == "200"){
                            var tagsList = res.data;
                            var tagHtml = '';
                            for(var i=0; i<tagsList.length; i++){
                                tagHtml += '<p><b>'+tagsList[i].tagname+'</b><i data-tagid="'+tagsList[i].tagid+'">DELETE</i></p>';
                            }
                            $(".tanchuang .tanchuang_con dl dd").html(tagHtml);
                            alert("新增标签成功");
                        }else{
                            alert(res.message);
                        }
                    },
                    error:function(err){
                        alert("请求服务出错");
                    }
                });
            }
        });

        //删除标签
        $(document).on("click",".tanchuang .tanchuang_con dl dd p i", function(){
            var tagId = $(this).attr("data-tagid");
            $.ajax({
                type: 'POST',
                url:"/joinweixinapp/1/deleteTag",
                data:{"tagId":tagId},
                success:function(res){
                    if(res.code == "200"){
                        var tagsList = res.data;
                        var tagHtml = '';
                        for(var i=0; i<tagsList.length; i++){
                            tagHtml += '<p><b>'+tagsList[i].tagname+'</b><i data-tagid="'+tagsList[i].tagid+'">DELETE</i></p>';
                        }
                        $(".tanchuang .tanchuang_con dl dd").html(tagHtml);
                        alert("删除标签成功");

                    }else{
                        alert(res.message);
                    }
                },
                error:function(err){
                    alert("请求服务出错");
                }
            });
        });


        //测试登录
        $(".tanchuang .login").on("click",function(){
            console.log("测试登录");
            var userinfo = {
                avatarUrl:"https://thirdwx.qlogo.cn/mmopen/vi_32/DYAIOgq83epZCzYccqaO0rZvMMRAAZEUN14SJ0VniaibM7g2Vz3ribkHjO2YZicGibZO7SPlnQXAbPEIcLHkM02LBOg/132",
                city:"普陀",
                country:"中国",
                gender:1,
                language:"zh_CN",
                nickName:"Sheldon",
                province:"上海"
            };
            var newData = {
                code: "051XTu000HHE8L1kfe4009RqRM0XTu0r",
                fasongId: 1,
                userInfo: JSON.stringify(userinfo),
            };
            $.ajax({
                type: 'POST',
                url:"/joinweixinapp/login",
                data: newData,
                success:function(res){
                console.log(res);
                    if(res.code == "200"){

                    }else{
                        alert(res.message);
                    }
                },
                error:function(err){
                    alert("请求服务出错");
                }
            });
        });

    });




</script>


</body>
</html>
